# -*- coding:utf-8 -*-
# __auther__='jiangkai'

import selenium.webdriver
from selenium.webdriver.support.ui import Select
from time import sleep
import os
from extScript.UploadPic import UploadPic


class SYTT:
    def __init__(self):
        pass

    def test_sytt(self, driver, dist=None):
        Select(driver.find_element_by_id("immovablesClass")).select_by_visible_text(u"水域滩涂养殖权")
        driver.find_element_by_id("immovablesDetail").clear()
        driver.find_element_by_id("immovablesDetail").send_keys(dist["不动产具体描述"])
        Select(driver.find_element_by_id("immovablesGetWay")).select_by_visible_text(dist["不动产取得方式"])

        driver.find_element_by_id("immovablesLoc").clear()
        driver.find_element_by_id("immovablesLoc").send_keys(dist["不动产坐落"])
        driver.find_element_by_id("immovablesArea").clear()
        driver.find_element_by_id("immovablesArea").send_keys(dist["面积"])

        if dist["证件类型"] == "不动产证号":
            driver.find_element_by_id("immovablesNo").clear()
            driver.find_element_by_id("immovablesNo").send_keys(dist["不动产证号"])
            driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("immovablesLoc"))
        else:
            driver.find_element_by_id("mudflatNo").clear()
            driver.find_element_by_id("mudflatNo").send_keys(dist['权证编号'])
            driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("immovablesLoc"))


        Select(driver.find_element_by_id("businessProject")).select_by_visible_text(dist['经营项目'])
        Select(driver.find_element_by_id("circulationType2")).select_by_visible_text(dist['流转性质'])

        driver.find_element_by_id("copy16").click()
        sleep(1)

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[14]/div[5]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["养殖证电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[14]/div[5]/div[3]/div[1]/div[1]/div[2]/a")

        # driver.find_element_by_xpath('/html/body/content/div[1]/form/div/div[14]/div[5]/a[2]').click()
        sleep(2)

        driver.find_element_by_id("copy17").click()
        sleep(2)
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id('copy16'))
        sleep(1)
        UploadPic(driver, "/html/body/content/div[1]/form/div/div[14]/div[8]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["水域滩涂养殖权流转合同电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[14]/div[8]/div[3]/div[1]/div[1]/div[2]/a")

        sleep(2)
        driver.find_element_by_name("waterBreedingRight.authorization").click()
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id('copy17'))
        sleep(1)

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[14]/div[11]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["书面意见电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[14]/div[11]/div[3]/div[1]/div[1]/div[2]/a")

        # driver.find_element_by_xpath('/html/body/content/div[1]/form/div/div[14]/div[11]/a[2]').click()



        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)

        driver.find_element_by_name("interestedPartyView").click()
        # 选择利害关系人意见证明材料上传
        UploadPic(driver, "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["利害关系人意见证明材料"]).upfile(
            "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/a")
        sleep(1)
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)
        driver.find_element_by_id("textarea2").clear()
        driver.find_element_by_id("textarea2").send_keys(dist["备注"])
        driver.find_element_by_id("next-step2").click()


if __name__ == '__main__':
    a = SYTT()
    a.test_sytt()
